import React, { PureComponent } from 'react';

import { CSSTransition } from 'react-transition-group'

import { Card, Avatar } from 'antd';
import { EditOutlined, EllipsisOutlined, SettingOutlined } from '@ant-design/icons';

import './CSSTransition.css'
const { Meta } = Card;

export default class CSSTransitionDemo extends PureComponent {
  constructor(props) {
    super(props)

    this.state = {
      isDisplay: true
    }
  }

  render() {
    return (
      <div>
        <button onClick={e => this.changeDisplay()}>Display/Hide</button>
        <CSSTransition in={this.state.isDisplay}
            classNames="card"
            timeout={300}
            unmountOnExit={true}
            appear
            onEnter={ el => {console.log('进入状态', el)} }>
          <Card
            style={{ width: 300 }}
            cover={
              <img
                alt="example"
                src="https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png"
              />
            }
            actions={[
              <SettingOutlined key="setting" />,
              <EditOutlined key="edit" />,
              <EllipsisOutlined key="ellipsis" />,
            ]}
          >
            <Meta
              avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
              title="Card title"
              description="This is the description"
            />
          </Card>
        </CSSTransition>
      </div>
    )
  }

  changeDisplay() {
    this.setState({
      isDisplay: !this.state.isDisplay
    })
  }
}